package com.hhss.qishi.service.system.impl;
 
import com.hhss.qishi.entity.system.User;
import com.hhss.qishi.entity.system.UserSecurity;
import com.hhss.qishi.mapper.system.UserMapper;
import com.hhss.qishi.service.impl.CommonServiceImpl;
import com.hhss.qishi.service.system.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
 
/**
 * @ClassName cn.saytime.service.impl.UserServiceImpl
 * @Description
 */
@Service
public class UserServiceImpl extends CommonServiceImpl<User, Serializable> implements UserService, UserDetailsService {
 
	@Autowired
	private UserMapper userMapper;
 
	@Override
	public List<User> getList(User user) {
		return userMapper.getList(user);
	}
 
	public User getUserRoleById(User user) {
		return userMapper.getUserRoleById(user);
	}
	
	/**
	 * UserDetailsService 根据用户名称查找对应的用户及其角色
	 */
	@Override
	public UserSecurity loadUserByUsername(String username) throws UsernameNotFoundException {
		User user = new User();
		// 设置登录名
		user.setLoginId(username);
		user = userMapper.getUserRoleById(user);
		if(user == null) {
			return null;
		}
		return new UserSecurity(user);
	}
}
